#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(){
  int n,q,flag,i,j,p;
  cin>>n>>q;
  vector<string> store(n);
  for(auto &x:store)cin>>x;
  while (q--)
  {
    cin>>flag;
    if(flag==1){
      cin>>i>>j>>p;
      store[j-1].insert(p,store[i-1]);
    } else{
      cin>>i;
      cout<<store[i-1]<<endl;
    }
  }
}